package net.jueb.marshalling;
import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.Marshalling;
import org.jboss.marshalling.MarshallingConfiguration;
import io.netty.handler.codec.marshalling.DefaultMarshallerProvider;
import io.netty.handler.codec.marshalling.DefaultUnmarshallerProvider;
import io.netty.handler.codec.marshalling.MarshallerProvider;
import io.netty.handler.codec.marshalling.UnmarshallerProvider;

public class ProviderFactory {
	/**
	 * 获取解码器供应者
	 * @param factoryName  "serial"
	 * @param version 5
	 * @return
	 */
	public static UnmarshallerProvider getDecoderProvider(String factoryName,int version)
	{
		/**
		 * 构建Jboss Marshalling的UnmarshallerProvider
		 */
		final MarshallerFactory factory=Marshalling.getProvidedMarshallerFactory(factoryName);
		final MarshallingConfiguration configuration=new MarshallingConfiguration();
		configuration.setVersion(version);
		UnmarshallerProvider provider=new DefaultUnmarshallerProvider(factory, configuration);
		return provider;
		
	}
	
	/**
	 * 获取编码器供应者
	 * @param factoryName  "serial"
	 * @param version 5
	 * @return
	 */
	public static MarshallerProvider getEncoderProvider(String factoryName,int version)
	{
		/**
		 * 构建Jboss Marshalling的MarshallerProvider
		 */
		final MarshallerFactory factory=Marshalling.getProvidedMarshallerFactory(factoryName);
		final MarshallingConfiguration configuration=new MarshallingConfiguration();
		configuration.setVersion(version);
		MarshallerProvider provider=new DefaultMarshallerProvider(factory, configuration);
		return provider;
	}
}
